import './assets/styles'

import { type App as IApp, createApp } from 'vue'

import App from './App.vue'
import { useElementPlus, useErrorHandler } from './hooks'
import router from './router'

function renderApp(app: IApp) {
  app.use(router)

  useElementPlus(app)
  useErrorHandler(app)

  app.mount('#app')
}

let app: Nullable<IApp> = null

if (window.__POWERED_BY_WUJIE__) {
  window.__WUJIE_MOUNT = () => {
    app = createApp(App)

    renderApp(app)
  }
  window.__WUJIE_UNMOUNT = () => {
    app?.unmount()
  }
} else {
  app = createApp(App)

  renderApp(app)
}
